﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;


public partial class Stat_ClientStat : System.Web.UI.Page
{
    Usas.BLL.Cms.StatOperate so = new Usas.BLL.Cms.StatOperate();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StatInit();
            BIND();
        }
    }

    private void StatInit()
    {
        StatChartlet1.Visible = false;
        StatChartlet2.Visible = false;
        txtYears.Text = DateTime.Now.Year.ToString();
        txtMonths.Text = DateTime.Now.Month.ToString();
        txtDays.Text = DateTime.Now.Day.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BIND();
    }

    private void BIND()
    {
        StatChartlet1.Visible = true;
        StatChartlet2.Visible = true;

        ClientBind();
        BrowserBind();
       

    }

    private void ClientBind()
    {
        ArrayList XTitle = new ArrayList();

        ArrayList[] ChartData = new ArrayList[1];
        ChartData[0] = new ArrayList();

        string years = txtYears.Text.Trim().Length > 0 ? " and years=" + txtYears.Text.Trim() : "";
        string months = txtMonths.Text.Trim().Length > 0 ? " and months=" + txtMonths.Text.Trim() : "";
        string days = txtDays.Text.Trim().Length > 0 ? " and days=" + txtDays.Text.Trim() : "";

        DataSet ds1 = so.ClientStat(years, months, days);

        if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
            {
                XTitle.Add(ds1.Tables[0].Rows[i]["systemName"].ToString());
                //object b = ds1.Tables[0].Rows[i][""] == null || ds1.Tables[0].Rows[0][i].ToString() == "0" || ds.Tables[0].Rows[0][i].ToString() == "" ? "0" : ds.Tables[0].Rows[0][i].ToString();
                ChartData[0].Add(ds1.Tables[0].Rows[i]["clientcount"].ToString());
            }
        }
        StatChartlet1.ChartTitle.Text = (txtYears.Text.Trim().Length > 0 ? txtYears.Text.Trim() + "年" : "")
            + (txtMonths.Text.Trim().Length > 0 ? txtMonths.Text.Trim() + "月" : "")
            + (txtDays.Text.Trim().Length > 0 ? txtDays.Text.Trim() + "日" : "")
            + "时段客户端分析";
        StatChartlet1.YLabels.UnitText = "数量";
        StatChartlet1.XLabels.UnitText = "类型";

        StatChartlet1.InitializeData(ChartData, XTitle, null);
    }

    private void BrowserBind()
    {
        ArrayList XTitle = new ArrayList();

        ArrayList[] ChartData = new ArrayList[1];
        ChartData[0] = new ArrayList();

        string years = txtYears.Text.Trim().Length > 0 ? " and years=" + txtYears.Text.Trim() : "";
        string months = txtMonths.Text.Trim().Length > 0 ? " and months=" + txtMonths.Text.Trim() : "";
        string days = txtDays.Text.Trim().Length > 0 ? " and days=" + txtDays.Text.Trim() : "";



        DataSet ds1 = so.BrowserStat(years, months, days);

        if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
            {
                XTitle.Add(ds1.Tables[0].Rows[i]["browserName"].ToString());
                //object b = ds1.Tables[0].Rows[i][""] == null || ds1.Tables[0].Rows[0][i].ToString() == "0" || ds.Tables[0].Rows[0][i].ToString() == "" ? "0" : ds.Tables[0].Rows[0][i].ToString();
                ChartData[0].Add(ds1.Tables[0].Rows[i]["clientcount"].ToString());
            }
        }
        StatChartlet2.ChartTitle.Text = (txtYears.Text.Trim().Length > 0 ? txtYears.Text.Trim() + "年" : "")
            + (txtMonths.Text.Trim().Length > 0 ? txtMonths.Text.Trim() + "月" : "")
            + (txtDays.Text.Trim().Length > 0 ? txtDays.Text.Trim() + "日" : "")
            + "时段浏览器分析";
        StatChartlet2.YLabels.UnitText = "数量";
        StatChartlet2.XLabels.UnitText = "类型";

        StatChartlet2.InitializeData(ChartData, XTitle, null);
    }
}
